﻿Ext.define('Egitim.controller.AdminCtrl', {
	extend: 'Ext.app.Controller',
	models: ['ToplantiTutanagi', 'AnketTanimlama'],
	views: ['admin.ToplantiTutanagiForm', 'admin.ToplantiTutanagiList', 'AnketTanimlamaPanel'],
	stores: ['ToplantiTutanagi'],
	refs:[{
		ref: 'toplantiTutanagiForm',
		selector: 'toplantitutanagiform'
	}],
	init: function() {
		
		this.control({
			'toplantitutanagiform button[action=tamam]': {
				click: this.onTamamToplantiTutanagi
			}
		});
	},
	
	onTamamToplantiTutanagi: function (but){
		var form = but.up('form').getForm();
		if (form.isValid()) {
			form.submit({
				success: function(form, action) {
					but.up('form').showMessage (1, action.result.msg);
				},
				failure: function(form, action) {
					but.up('form').showMessage (0, action.result.msg);
				}
			});
		}	
	},
	
	onGuncelleEgitim: function (grid, record) {
		var egitimId = record.get('id'),
			adSoyad = record.get('ad') + ' ' + record.get('soyad');
		Ext.create('Ext.window.Window', {
			title: Ext.String.format('Eğitim [{0}] [{1}]', egitimId, adSoyad),
			modal: true,
			height: 400,
			width: 600,
			layout: 'fit',
			maximizable: true,
			items: {
				//xtype: 'egitimform',
				xtype: 'egitimpanel',
				egitimId: egitimId,
				title: '',
				border: false
			}
		}).show();
	},
	
	onAfterRender: function () {
		this.getEgitimStore().load();
	},
	
	onGosterEgitim: function (egitimForm){
		var egitimId = '';
		if (Ext.isEmpty(egitimForm.up('egitimpanel'))) {
			egitimId = egitimForm.egitimId
		} else {
			egitimId = egitimForm.up('egitimpanel').egitimId;
		}
		egitimForm.egitimId = egitimId;
		
		if (!Ext.isEmpty(egitimId)) {
			egitimForm.load({
				waitMsg: 'Yükleniyor',
				url: 'egitims/load/' + egitimId,
				method: 'POST'
			});
		}
	}
});